//
//  TSProgressView.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/15.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSProgressView: UIView {
    
    var progressContainer : UIView!
    var progressView : UIView!
    var startLabel : UILabel!
    var endLabel : UILabel!

    override init(frame: CGRect) {
        super.init(frame: frame)
        configViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupProgressView(value:CGFloat, start:String, end:String) {
        
        startLabel.text = start
        endLabel.text = end
        
        UIView.animate(withDuration: 2) {
            self.progressView.snp.updateConstraints { (make) in
                make.width.equalTo(self.progressContainer.frame.width*value)
//                make.width.equalToSuperview().multipliedBy(value)
            }
        }
        self.layoutIfNeeded()
    }
    
    func configViews() {
        
        startLabel = UILabel.init()
        startLabel.text = "VIP0"
        startLabel.font = UIFont.systemFont(ofSize: 10, weight: .medium)
        startLabel.textColor = BASE_RED_COLOR
        addSubview(startLabel)
        startLabel.snp.makeConstraints { (make) in
            make.left.equalTo(32)
            make.top.equalToSuperview()
        }
        
        endLabel = UILabel.init()
        endLabel.text = "VIP1"
        endLabel.font = UIFont.systemFont(ofSize: 10, weight: .medium)
        endLabel.textColor = BASE_RED_COLOR
        addSubview(endLabel)
        endLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(startLabel)
            make.right.equalToSuperview().inset(32)
        }
        
        progressContainer = UIView.init()
        progressContainer.backgroundColor = UIColor.hexadecimalColor(hexadecimal: "#DBE0EA")
        progressContainer.layer.cornerRadius = 4
        progressContainer.layer.masksToBounds = true
        addSubview(progressContainer)
        progressContainer.snp.makeConstraints { (make) in
            make.centerY.equalTo(startLabel)
            make.height.equalToSuperview()
            make.left.equalTo(startLabel.snp.right).offset(10)
            make.right.equalTo(endLabel.snp.left).offset(-10)
        }
        
        progressView = UIView.init()
        progressView.backgroundColor = BASE_RED_COLOR
        progressView.layer.cornerRadius = 4
        progressView.layer.masksToBounds = true
        progressContainer.addSubview(progressView)
        progressView.snp.makeConstraints { (make) in
            make.top.bottom.left.equalToSuperview()
            make.width.equalTo(0)
        }
    }
}
